package com.michael.demo.springcloud.alibaba.seata.upms.controller;


import com.michael.demo.springcloud.alibaba.seata.upms.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * 类功能描述:
 * <pre>
 *   xxxx
 * </pre>
 *
 * @author Michael
 * @version 1.0
 * @date 2021/04/01 17:00
 */
@Slf4j
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping("/deduct/{userId}/{money}")
    String deduct(@PathVariable("userId") Long userId, @PathVariable("money") Integer money) {
        boolean result = accountService.deductByUserId(userId, money);

        //Random random = new Random();
        //if (random.nextBoolean()) {
        //    throw new RuntimeException("AccountController 模拟异常");
        //}

        return  result? "SUCCESS" : "FAILURE";
    }

}
